local caixia = fk.CreateSkill {
    name = "gai__caixia",
  }
  
  Fk:loadTranslationTable{
    ["gai__caixia"] = "才瑕",
    [":gai__caixia"] = "当你受到伤害后，你可以摸至多2张牌。若如此做，此技能失效直到你累计使用了等量的牌。",
  
    ["#caixia-draw"] = "才瑕：你可以摸至多2张牌，此技能失效直到你使用等量张牌",
    ["@caixia"] = "才瑕",
  
    ["$gai__caixia1"] = "吾习扫天下之术，不善净一屋之秽。",
    ["$gai__caixia2"] = "玉有十色五光，微瑕难掩其瑜。",
  }
  
  local spec = {
    anim_type = "masochism",
    can_trigger = function(self, event, target, player, data)
      return target == player and player:hasSkill(caixia.name) and player:getMark("@caixia") == 0
    end,
    on_cost = function(self, event, target, player, data)
      local room = player.room
      local choices = {}
      for i = 1, 2, 1 do  -- 直接固定为2张
        table.insert(choices, tostring(i))
      end
      table.insert(choices, "Cancel")
      local choice = room:askToChoice(player, {
        choices = choices,
        skill_name = caixia.name,
        prompt = "#caixia-draw",
      })
      if choice ~= "Cancel" then
        event:setCostData(self, {choice = tonumber(choice)})
        return true
      end
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      local n = event:getCostData(self).choice
      room:setPlayerMark(player, "@caixia", n)
      room:invalidateSkill(player, caixia.name)
      player:drawCards(n, caixia.name)
    end,
  }
  
  caixia:addEffect(fk.Damaged, spec)
  
  caixia:addEffect(fk.CardUsing, {
    mute = true,
    can_trigger = function(self, event, target, player, data)
      if player ~= target or player:getMark("@caixia") == 0 then return end
      local skillName = caixia.name
      --FIXME：须无视自身的封锁，这种写法很愚蠢
      local record = player:getTableMark(MarkEnum.InvalidSkills)
      if record[skillName] and table.contains(record[skillName], skillName) then
        local room = player.room
        room:validateSkill(player, skillName)
        local can_invoke = player:hasSkill(skillName)
        room:invalidateSkill(player, skillName)
        return can_invoke
      end
    end,
    on_cost = Util.TrueFunc,
    on_use = function(self, event, target, player, data)
      local room = player.room
      room:removePlayerMark(player, "@caixia")
      if player:getMark("@caixia") < 1 then
        room:validateSkill(player, caixia.name)
      end
    end,
  })
  
  caixia:addLoseEffect(function (self, player, is_death)
    local room = player.room
    room:validateSkill(player, caixia.name)
    room:setPlayerMark(player, "@caixia", 0)
  end)
  
  return caixia